//
//  RNTLaunchView.m
//  rzc_app
//
//  Created by 孙磊 on 2019/5/15.
//  Copyright © 2019 Facebook. All rights reserved.
//

#import "RNTLaunchView.h"
#import <React/RCTConvert.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventDispatcher.h>
#import <React/UIView+React.h>


@implementation RNTLaunchView
{
  RCTEventDispatcher *_eventDispatcher;
}

- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher {
  if ((self = [super init])) {
    _eventDispatcher = eventDispatcher;
  }
  [self addSubview:self.lanuchImageView];
  return self;
}
- (UIImageView *)lanuchImageView {
   if (!_lanuchImageView) {
    _lanuchImageView = [[UIImageView alloc] initWithImage:[self getLaunchImage]];
     [_lanuchImageView setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
   }
   return _lanuchImageView;
  
}
- (UIImage *)getLaunchImage {
  CGSize viewSize = [UIScreen mainScreen ].bounds.size;
  NSString *viewOrientation = @"Portrait";    //横屏请设置成 @"Landscape"
  NSString *launchImage = nil;
  NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
  for (NSDictionary* dict in imagesDict)
  {
    CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
    
    if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]])
    {
      launchImage = dict[@"UILaunchImageName"];
    }
  }
  return [UIImage imageNamed:launchImage];
}
-(void)layoutSubviews{
  [super layoutSubviews];
  self.lanuchImageView.frame = self.bounds;
}
@end
